﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace PRO_DOCS.DAL.Database
{
    public class MainClass
    {
        internal DataSet getDataSet(string sp_name, Dictionary<string,string> paramValues)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter();
            SqlCommand sqlcmd = new SqlCommand();
            DataSet set = new DataSet();
            try
            {
                sqlcmd.Connection = new SqlConnection(Properties.Settings.Default.PRO_DOCSConnectionString);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.CommandText = sp_name;
                if (paramValues.Count > 0)
                {
                    SqlParameter sqlparam = new SqlParameter();
                    foreach (KeyValuePair<string,string> sqlParam in paramValues)
                    {
                        sqlcmd.Parameters.AddWithValue(sqlParam.Key, sqlParam.Value);
                    }
                }

                sqlda.SelectCommand = sqlcmd;
                sqlda.Fill(set);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            finally
            {
                if (sqlcmd.Connection.State == ConnectionState.Open)
                    sqlcmd.Connection.Close();
            }
            return set;
        } 

        private static DAL.Database.PRO_DOCSDatabaseDataContext _PRO_DOCSDatabaseDataContext;
        /// <summary>
        /// Gets or sets the cargill egypt database data context.
        /// </summary>
        /// <value>The cargill egypt database data context.</value>
        public static DAL.Database.PRO_DOCSDatabaseDataContext PRO_DOCSDatabaseDataContext
        {
            get
            {
                _PRO_DOCSDatabaseDataContext = new PRO_DOCSDatabaseDataContext(Properties.Settings.Default.PRO_DOCSConnectionString);
                return _PRO_DOCSDatabaseDataContext;
            }
            set { _PRO_DOCSDatabaseDataContext = value; }
        }
    }
}
